<?php
App::uses('AppController', 'Controller');
/**
 * VenueGalleries Controller
 *
 * @property VenueGallery $VenueGallery
 * @property PaginatorComponent $Paginator
 */
class VenueGalleriesController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');

/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index($venue_id = null) {
		$this->VenueGallery->recursive = 0;
		$venue = $this->VenueGallery->Venue->findById($venue_id);
		$this->set('venue',$venue);
		$this->set('venueGalleries', $this->Paginator->paginate('VenueGallery',array('VenueGallery.venue_id'=>$venue_id)));
	}


/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add($venue_id = null) {
		if ($this->request->is('post')) {
			$this->VenueGallery->create();
			if ($this->VenueGallery->save($this->request->data)) {
				$this->Session->setFlash(__('添加成功'),'tip/tip_float',array('t'=>'success'));
				return $this->redirect(array('action' => 'index',$venue_id));
			} else {
				if($this->request->data['Venue']['sys_photo_id']){
					$photo = $this->VenueGallery->SysPhoto->findById($this->request->data['VenueGallery']['sys_photo_id']);
					$this->request->data['SysPhoto'] = $photo['SysPhoto'];
				}
				$this->Session->setFlash(__('添加失败，请重试'),'tip/tip_float');
			}
		}
		$this->set('venue_id',$venue_id);
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		if (!$this->VenueGallery->exists($id)) {
			throw new NotFoundException(__('Invalid venue gallery'));
		}
		if ($this->request->is(array('post', 'put'))) {
			if ($this->VenueGallery->save($this->request->data)) {
				$this->Session->setFlash(__('修改成功'),'tip/tip_float',array('t'=>'success'));
				return $this->redirect(array('action' => 'index',$this->request->data['VenueGallery']['venue_id']));
			} else {
				if($this->request->data['Venue']['sys_photo_id']){
					$photo = $this->VenueGallery->SysPhoto->findById($this->request->data['VenueGallery']['sys_photo_id']);
					$this->request->data['SysPhoto'] = $photo['SysPhoto'];
				}
				$this->Session->setFlash(__('修改失败，请重试'),'tip/tip_float');
			}
		} else {
			$options = array('conditions' => array('VenueGallery.' . $this->VenueGallery->primaryKey => $id));
			$this->request->data = $this->VenueGallery->find('first', $options);
		}
	}

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		$this->VenueGallery->id = $id;
		if (!$this->VenueGallery->exists()) {
			throw new NotFoundException(__('Invalid venue gallery'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->VenueGallery->delete()) {
			$this->Session->setFlash(__('The venue gallery has been deleted.'));
		} else {
			$this->Session->setFlash(__('The venue gallery could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	}}
